package com.neuedu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.neuedu.pojo.AdminTable;
import com.neuedu.pojo.Declaration;
import com.neuedu.pojo.Result;
import com.neuedu.service.DeclarationService;
import com.neuedu.mapper.DeclarationMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
* @author Administrator
* @description 针对表【declaration(自主申报表)】的数据库操作Service实现
* @createDate 2025-06-18 15:45:31
*/
@Service
public class DeclarationServiceImpl extends ServiceImpl<DeclarationMapper, Declaration>
    implements DeclarationService{
    @Autowired
    private DeclarationMapper declarationMapper;

    @Override
    public Result<Void> addDeclaration(Declaration declaration) {
        declaration.setFamilyId(4);
        declaration.setIsDelete(0);
        declaration.setCreateTime(new Date());
        declaration.setUpdateTime(new Date());
        // 添加
        int insert = this.declarationMapper.insert(declaration);
        if (insert > 0){
            return Result.success();
        }
        return Result.fail();
    }

    @Override
    public Result<Declaration> getDeclarationByFid(Integer fid) {
        Declaration declaration = declarationMapper.selectById(fid);
        if (declaration !=null){
            return Result.success(declaration);
        }
        return Result.fail();
    }

    @Override
    public Result<Void> deleteDeclaration(Integer id) {
        LambdaUpdateWrapper<Declaration> wrapper = new LambdaUpdateWrapper<>();
        wrapper.set(Declaration::getIsDelete,1)
                .eq(Declaration::getDeclarationId,id);
        int update = this.declarationMapper.update(wrapper);
        if (update > 0){
            return Result.success();
        }
        return Result.fail();
    }

    @Override
    public Result<Void> updateDeclaration(Declaration declaration) {
        declaration.setUpdateTime(new Date());
        // 添加
        int insert = this.declarationMapper.updateById(declaration);
        if (insert > 0){
            return Result.success();
        }
        return Result.fail();
    }

    @Override
    public Result<Integer> selectDeclarationByCard(String card) {
        Declaration declaration=declarationMapper.selectByCard(card);
        int declarationId=declaration.getDeclarationId();
        return Result.success(declarationId);
    }
}




